import requests

# url = "http://httpbin.org/get"
#
# params = {
#     "user": "king",
#     "age": 18
# }
#
# headers = {
#     "User-Agent": "Mozilla/5.0",
#     "m-xkw": "12344567"
# }
#
# cookie = {
#     "user": "wangyong"
# }

# req = requests.get(url=url, params=params, headers=headers)
# print(req.status_code)
# # print(req.json()['args']['user'])
# # print(req.url)
# print(req.text)
# print(req.cookies)
# for k,v in req.cookies.items():
#     print(k,v)

# print(req.status_code)
# print(req.headers)
# print(req.text)
# print(req.cookies)


# req = requests.post(url="http://httpbin.org/post", data=params)
# print(req.status_code)
# print(req.json())


# req = requests.get(url="http://httpbin.org/cookies", cookies=cookie, timeout=0.1)
# print(req.text)
# print(req.cookies)
# print(req.elapsed.total_seconds())


# file = {
#     'file': open("test.png", 'rb')
# }
#
# req = requests.post("http://httpbin.org/post", files=file)
# print(req.text)


# 创建一个会话
# s = requests.Session()
#
# req = s.get("http://httpbin.org/cookies/set/user/king")  # 登录接口
# print(req.text)
#
# req = s.get("http://httpbin.org/cookies")  # 查看用户信息
# print(req.text)


#  SSL证书验证
# req = requests.get("https://www.12306.cn/index/", verify=False)
# print(req.text)


#  代理设置
# url = "https://www.lagou.com/jobs/positionAjax.json?needAddtionalResult=false"
# data = {
#     "first": True,
#     "pn": "1",
#     "kd": "测试工程师"
# }
#
# headers = {
#     "content-type": "application/x-www-form-urlencoded; charset=UTF-8",
#     "user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36",
#     "referer": "https://www.lagou.com/jobs/list_%E6%B5%8B%E8%AF%95%E5%B7%A5%E7%A8%8B%E5%B8%88?labelWords=&fromSearch=true&suginput="
# }
#
# proxies = [
#     {"http": "http://52.91.116.132:80"},
#     {"http": "http://52.91.116.132:80"},
#     {"http": "http://52.91.116.132:80"},
# ]
#
#
# url = "http://httpbin.org/post"
# req = requests.post(url=url, data=data,proxies=proxies[0])
# print(req.text)

#  身份认证
# from requests.auth import HTTPBasicAuth,HTTPDigestAuth

# URL = "http://httpbin.org/basic-auth/king/123456"
# req = requests.get(url=URL, auth = HTTPBasicAuth('king', '123456'))
# print(req.status_code)
# print(req.text)

# req = requests.get('http://httpbin.org/digest-auth/auth/wangyong/666666',auth= HTTPDigestAuth('wangyong','666666'))
# print(req.text)

# http://httpbin.org/stream/1
import json

# url = "https://www.baidu.com/"
# req = requests.get(url=url)
# print(req.encoding)
# req.encoding = 'utf-8'
# print(req.text)

# if req.encoding is None:
#     req.encoding = 'utf-8'

# for line in req.iter_lines(decode_unicode=True):
#     if line:
#         # print("line----", line)
#         # print(type(line))
#         data = json.loads(line)
#         print(data['id'])
        # print("data", type(data))

# print(req.text)

url= "http://httpbin.org/"
data = {'user': 'king'}
cookies = {}
req = requests.post(url=url + 'post', data=data, cookie=cookies)
print(req.text)
# response_data = req.json()
# print(response_data)
# print(response_data['args']['user'])

